package com.crazyhat.crazyhat.vaildation;

import com.crazyhat.crazyhat.anno.SensitiveWordAnno;
import com.github.houbb.sensitive.word.bs.SensitiveWordBs;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;

/**
 * 敏感词校验
 */
public class SensitiveWordValidation implements ConstraintValidator<SensitiveWordAnno,String> {

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        
        if (value==null) {
            return true;
        }

        boolean hasSensitiveWord=SensitiveWordBs.newInstance().init().contains(value);

        if (hasSensitiveWord) {

            //如果含有敏感词
            
            return false;
        } else {
            return true;
        }
    }
    
    
}
